#!/bin/bash

echo "========================================"
echo "Starting SmartCode Services"
echo "(OpenHarmony C++ Intelligence Platform)"
echo "========================================"

# 启动MCP Server
echo "Starting MCP Server..."
if [ -d "mcp-server/node_modules" ]; then
    cd mcp-server
    npm run dev > ../logs/mcp-server.log 2>&1 &
    cd ..
    sleep 5
else
    echo "MCP dependencies not installed, skipping..."
fi

# 启动Data Service
echo "Starting Data Service..."
cd data-service
mvn spring-boot:run > ../logs/data-service.log 2>&1 &
cd ..
sleep 10

# 启动LLM Service
echo "Starting LLM Service..."
cd llm-service
mvn spring-boot:run > ../logs/llm-service.log 2>&1 &
cd ..
sleep 10

# 启动Build Service
echo "Starting Build Service..."
cd build-service
mvn spring-boot:run > ../logs/build-service.log 2>&1 &
cd ..
sleep 10

# 启动Code Completion Service
echo "Starting Code Completion Service..."
cd code-completion-service
mvn spring-boot:run > ../logs/code-completion-service.log 2>&1 &
cd ..
sleep 5

# 启动Code Generation Service
echo "Starting Code Generation Service..."
cd code-generation-service
mvn spring-boot:run > ../logs/code-generation-service.log 2>&1 &
cd ..
sleep 5

# 启动Code Analysis Service
echo "Starting Code Analysis Service..."
cd code-analysis-service
mvn spring-boot:run > ../logs/code-analysis-service.log 2>&1 &
cd ..
sleep 5

# 启动Gateway
echo "Starting Gateway..."
cd gateway
mvn spring-boot:run > ../logs/gateway.log 2>&1 &
cd ..

echo "========================================"
echo "All services are starting..."
echo "Gateway will be available at: http://localhost:8080"
echo "Check logs in ./logs directory"
echo "========================================"

